<html>
<head><meta charset="utf-8"><title>Get function name from Expr call · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20function.20name.20from.20Expr.20call.html">Get function name from Expr call</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="238177215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20function%20name%20from%20Expr%20call/near/238177215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BaSh <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20function.20name.20from.20Expr.20call.html#238177215">(May 10 2021 at 17:06)</a>:</h4>
<p>Hello, <br>
Is there a better way to get the function name of an Expr call?</p>
<p>Currently, I'm getting the function name like in an ugly way like this <code>self.sess.source_map().span_to_snippet(expr.span).unwrap().split("(").collect::&lt;Vec&lt;&amp;str&gt;&gt;()[0].to_string();</code></p>



<a name="238205232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20function%20name%20from%20Expr%20call/near/238205232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20function.20name.20from.20Expr.20call.html#238205232">(May 10 2021 at 20:19)</a>:</h4>
<p>Start with <code>match expr.kind</code> and look for <code>ExprKind::Call</code> or <code>ExprKind::MethodCall</code></p>



<a name="238205383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20function%20name%20from%20Expr%20call/near/238205383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20function.20name.20from.20Expr.20call.html#238205383">(May 10 2021 at 20:20)</a>:</h4>
<p>If it's MethodCall, the first element is PathSegment which has Ident</p>



<a name="238205807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20function%20name%20from%20Expr%20call/near/238205807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20function.20name.20from.20Expr.20call.html#238205807">(May 10 2021 at 20:23)</a>:</h4>
<p>If it's a Call, the first element is another expr which (usually) has <code>ExprKind::Path(QPath)</code> and you can destructure the <code>QPath</code> further to find a PathSegment.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>